package com.ht.config;

import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuertzConfig {

    @Bean
    public JobDetail jobDetail(){
        JobDetail  build = JobBuilder.newJob(QuertzJob.class)//绑定QuertzJob   QuertzJob---需要自定义并且继承QuartzJobBean
                .withIdentity("job", "jobGroup")//定义job的名称,以及它所在的组
                .usingJobData("jobKey", "jobKey的值")//定义要打印的的数据key,以及他的值
                .storeDurably()//不放会报错
                .build();
        return  build;
    }

    @Bean
    public Trigger trigger(){
        CronTrigger build = TriggerBuilder.newTrigger()
                .forJob(jobDetail())//绑定jobDetail
                .withIdentity("trigger", "triggerGroup")//定义trigger的名字,以及它所在的组
                .usingJobData("triggerKey", "trigeerKey的值")//定义triggerkey的key,以及key所对应的值
                .withSchedule(CronScheduleBuilder.cronSchedule("0 0 0 * * ? *"))
                .build();
        return build;
    }
}
